﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using JetBrains.ReSharper.TaskRunnerFramework;

namespace Objectware.Silverlight.Testing.Runner.Resharper.Tasks
{
	[Serializable]
	public class ClassTask : RemoteTask, IEquatable<ClassTask>
	{
        readonly string assemblyLocation;
        readonly bool explicitly;
        readonly string typeName;

        public ClassTask(XmlElement element)
            : base(element)
        {
            typeName = GetXmlAttribute(element, "TypeName");
            assemblyLocation = GetXmlAttribute(element, "AssemblyLocation");
            explicitly = GetXmlAttribute(element, "Explicitly") == "true";
        }

        public ClassTask(string assemblyLocation,
                                  string typeName,
                                  bool explicitly)
            : base("Silverlight")
        {
            if (typeName == null)
                throw new ArgumentNullException("typeName");

            this.assemblyLocation = assemblyLocation;
            this.typeName = typeName;
            this.explicitly = explicitly;
        }

        public string AssemblyLocation
        {
            get { return assemblyLocation; }
        }

        public bool Explicitly
        {
            get { return explicitly; }
        }

        public string TypeName
        {
            get { return typeName; }
        }

        public bool Equals(ClassTask xunitTestClassTask)
        {
            if (xunitTestClassTask == null || !base.Equals(xunitTestClassTask))
                return false;

            return (Equals(assemblyLocation, xunitTestClassTask.assemblyLocation) &&
                    Equals(typeName, xunitTestClassTask.typeName) &&
                    explicitly == xunitTestClassTask.explicitly);
        }

        public override bool Equals(object obj)
        {
            return (this == obj || Equals(obj as ClassTask));
        }

        public override void SaveXml(XmlElement element)
        {
            base.SaveXml(element);
            SetXmlAttribute(element, "TypeName", TypeName);
            SetXmlAttribute(element, "AssemblyLocation", AssemblyLocation);
            SetXmlAttribute(element, "Explicitly", Explicitly ? "true" : "false");
        }
	}
}
